package ModelLayer;

import java.util.*;
public class SessionContainer
{
    private ArrayList<Session>  sessionContainer;
    private static SessionContainer instance;

    private SessionContainer()
    {
        sessionContainer = new  ArrayList<Session>();
    }

    public static SessionContainer getInstance(){
        if (instance == null){
            instance = new SessionContainer();
        }
        return instance;
    }
  
    public Session findSessionById(int id){
        Session pObject = null;
        int index = 0;
        boolean found = false;
        while(index < sessionContainer.size() && !found)
        {
            pObject = sessionContainer.get(index); 
            if(pObject.getSessionId() == id)
            {
                found = true;
            }
            else{
                index++;
            }
        }
        if(found){
           return sessionContainer.get(index) ;
        }else{
            return  null;
        }
    }
    
    public ArrayList<Session> getSessionList(){
        return this.sessionContainer;
    }
   
//     public void endSession(int sessionId){
//         findSessionById(sessionId).setActive(false);
//     }
//     
    public void addSession(Session p){
        sessionContainer.add(p);
    }

    public void deleteSession(Session p){
        if(sessionContainer.contains(p))
            sessionContainer.remove(p);
    }
}
